/*!
 * classie - class helper functions
 * from bonzo https://github.com/ded/bonzo
 * 
 * classie.has( elem, 'my-class' ) -> true/false
 * classie.add( elem, 'my-new-class' )
 * classie.remove( elem, 'my-unwanted-class' )
 * classie.toggle( elem, 'my-class' )
 */

/*jshint browser: true, strict: true, undef: true */

( function( window ) {

'use strict';

// class helper functions from bonzo https://github.com/ded/bonzo

function classReg( className ) {
  return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
}

// classList support for class management
// altho to be fair, the api sucks because it won't accept multiple classes at once
var hasClass, addClass, removeClass;

if ( 'classList' in document.documentElement ) {
  hasClass = function( elem, c ) {
    return elem.classList.contains( c );
  };
  addClass = function( elem, c ) {
    elem.classList.add( c );
  };
  removeClass = function( elem, c ) {
    elem.classList.remove( c );
  };
}
else {
  hasClass = function( elem, c ) {
    return classReg( c ).test( elem.className );
  };
  addClass = function( elem, c ) {
    if ( !hasClass( elem, c ) ) {
      elem.className = elem.className + ' ' + c;
    }
  };
  removeClass = function( elem, c ) {
    elem.className = elem.className.replace( classReg( c ), ' ' );
  };
}

function toggleClass( elem, c ) {
  var fn = hasClass( elem, c ) ? removeClass : addClass;
  fn( elem, c );
}

window.classie = {
  // full names
  hasClass: hasClass,
  addClass: addClass,
  removeClass: removeClass,
  toggleClass: toggleClass,
  // short names
  has: hasClass,
  add: addClass,
  remove: removeClass,
  toggle: toggleClass
};

})( window );


/*!
 * -----------------------
 * 右弹出侧边栏
 * -----------------------
 */

var menuRight = document.getElementById('z-spmenu-right'),
	showRight = document.getElementById('showRight'),
	showRightPush = document.getElementById('showRightPush'),
	body = document.body;

if(showRight){
    showRight.onclick = function() {
        classie.toggle(this, 'active');
        classie.toggle(menuRight, 'z-spmenu-open');
        disableOther('showRight');
    };
}

if(showRightPush){
    showRightPush.onclick = function() {
        classie.toggle(this, 'active');
        classie.toggle(body, 'z-spmenu-push-toleft');
        classie.toggle(menuRight, 'z-spmenu-open');
        disableOther('showRightPush');
    };
}

function disableOther(button) {
	if(button !== 'showRight') {
		classie.toggle(showRight, 'am-disabled');
	}
	if(button !== 'showRightPush') {
		classie.toggle(showRightPush, 'am-disabled');
	}
}
$(function(){
    /***
     * 显示隐藏金额数字
     */
    $('#eyes').click(function(){
        var eyesVal = $(".eye-val");
        eyesVal.each(function(){
            if($(this).html() == "***"){
                $(this).html($(this).data('account'));
                $("#eyes i").removeClass("icon-hidden");
                $("#eyes i").addClass("icon-eye ");
            } else{
                $(this).html("***");
                $("#eyes i").addClass("icon-hidden");
                $("#eyes i").removeClass("icon-eye ");
            }
        })
        // console.log(eyesVal);
    });

    /***
     * 完善个人信息弹出层
     */
    $("#green-modal").modal({
        closeViaDimmer: 0,
        width: 400
    });

    /**
     * 签到弹出层
     */
    $(".sign-in").on('click',function(){
        $("#signiIn-modal").modal({
            closeViaDimmer: 0,
            width:400
        });
    });

    /***
     * 下拉列表框
     */
    $(".select-wrap").each(function(e){
        var $this = $(this);
        $(this).hover(function(){
            var li = $this.children('.select-list').children('li').children('a');

            $this.addClass('select-click');
            $this.children('.select-txt').children('i').removeClass("icon-arrow-down");
            $this.children('.select-txt').children('i').addClass("icon-arrow-top");

            li.click(function(){
                var txts = $(this).html();
                var headTxt = $(this).parent().parent().siblings().children('span');
                headTxt.html(txts);
                $(this).parents('.select-wrap').removeClass('select-click');
            });
        },function(){
            $this.removeClass('select-click');
            $this.children('.select-txt').children('i').addClass("icon-arrow-down");
            $this.children('.select-txt').children('i').removeClass("icon-arrow-top");
        })
    })
});
(function($) {
    if ($.AMUI && $.AMUI.validator) {
        // 增加身份证正则
        $.AMUI.validator.patterns.regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;

    }
})(window.jQuery);